<template>
  <div class="app-container">
    <el-card>
      <el-form
          :model="queryParams"
          ref="queryRef"
          :inline="true"
          v-show="showSearch"
      >
        <el-form-item label="申请编号">
          <el-input
              v-model="queryParams.applyCode"
              placeholder="请输入申请编号"
              clearable
              @keyup.enter="handleQuery"
          />
        </el-form-item>

        <el-form-item label="老人姓名">
          <el-input
              v-model="queryParams.applyName"
              placeholder="请输入老人姓名"
              clearable
              @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="签约状态">
          <el-select
              v-model="queryParams.signStatus"
              clearable
              placeholder="请选择状态"
              style="width: 240px"
          >
            <el-option
                v-for="dict in contracted_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
          >
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <right-toolbar
            v-model:showSearch="showSearch"
            @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="postList" stripe border max-height="500">
        <el-table-column label="申请编号" align="center" prop="applyCode"  width="200" />
        <el-table-column label="老人姓名" align="center" prop="applyName" width="100" />
        <el-table-column label="性别" align="center" width="100" >
          <template #default="scope">
        <span>
           {{sys_user_sex.find(item=>item.value==scope.row.sex)? sys_user_sex.find(item=>item.value==scope.row.sex).label:''}}
        </span>
          </template>
        </el-table-column>
        <el-table-column label="年龄" align="center" prop="age"   width="100" />
        <el-table-column label="家庭住址" align="center" prop="address"  width="500"/>
        <el-table-column label="签约状态" align="center" prop="commission" width="100">
          <template #default="scope">
        <span>
           {{contracted_status.find(item=>item.value==scope.row.signStatus)? contracted_status.find(item=>item.value==scope.row.signStatus).label:''}}
        </span>
          </template>
        </el-table-column>
        <el-table-column label="合同编号" align="center" prop="contractCode"  />
        <el-table-column label="签约时间" align="center" prop="signTime" width="160"/>

        <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button link type="primary" v-if="scope.row.signStatus=='0'" @click="edit(scope.row)">制定合同</el-button>
            <el-button link type="primary" v-if="scope.row.signStatus!=='0'" @click="edit(scope.row)">查看合同</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.page"
          v-model:limit="queryParams.limit"
          @pagination="getList"
      />
    </el-card>
    <!-- 添加或修改岗位对话框 -->
  </div>
</template>

<script setup name="evaluation">
  const { proxy } = getCurrentInstance();
  const {  sys_user_sex,contracted_status} = proxy.useDict(
      "sys_user_sex",
      "contracted_status"
  );
  const router = useRouter();
  import {contractSign} from '@/api/homebedsign/index'
  const showSearch = ref(true);
  const loading = ref(true);
  const postList = ref([]);
  const total = ref(0);

  const data = reactive({
    queryParams: {
      page: 1,
      limit: 10,
      applyCode: undefined,
      applyName:undefined,
      signStatus:undefined
    },

  });

  const { queryParams } = toRefs(data);

  /** 提交按钮 */
  function edit(data) {
    router.push({
      name:`contractAwardInfo`,
      params:{
        id:data.id,
      }
    })
  }

  /** 查询岗位列表 */
  function getList() {
    loading.value = true;
    contractSign(queryParams.value).then((response) => {
      postList.value = response.page.list;
      total.value = response.page.totalCount;
      loading.value = false;
    });
  }

  function handleQuery() {
    getList();
  }

  function resetQuery() {
    queryParams.value = {
      page: 1,
      limit: 10,
      applyCode: undefined,
      applyName:undefined,
      signStatus:undefined
    };
    getList();
  }

  getList();
</script>

